﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAO;
using DTO;
using System.Data.SqlClient;
namespace Banking.Quản_lý
{
    public partial class ThemNhanVien : UserControl
    {
        public ThemNhanVien()
        {
            InitializeComponent();
            init();
        }
        public void init()
        {
            List<TruSo> lstTruSo = TruSoDA.GetALl(0);
            cbbTruSo.DataSource = lstTruSo;
            cbbTruSo.DisplayMember = "Ten";
            cbbTruSo.ValueMember = "MaTruSo";
            List<GioiTinh> lstGioiTinh = GioiTinhDAO.GetALL();
            cbbGioiTinh.DataSource = lstGioiTinh;
            cbbGioiTinh.DisplayMember = "MoTa";
            cbbGioiTinh.ValueMember = "MaLoaiGioiTinh";

        }
        public void ThemNV()
        {
            NhanVien nv = new NhanVien();
            nv.TenNV = txtHoTen.Text;
            nv.NgaySinh =Convert.ToDateTime(dataNgaySinh.Text);
            nv.MoTa = txtMoTa.Text;
            nv.DienThoai =Convert.ToInt32(txtDienThoai.Text);
            nv.DiaChi = txtDiaChi.Text;
            nv.CMND = Convert.ToInt32(txtCMND.Text);
            nv.MaLoaiGioiTinh = cbbGioiTinh.SelectedIndex +1; 
            nv.MaTruSo = cbbTruSo.SelectedIndex + 1;
            TaiKhoanDangNhapNV taiKhoan = new TaiKhoanDangNhapNV();
            taiKhoan.TenDangNhap = txtTenDangNhap.Text;
            taiKhoan.MatKhau = txtMatKhau.Text;
            NhanVienDAO.InsertNhanVien(nv, taiKhoan);
            MessageBox.Show("Them nhan vien thanh cong");
        }

        private void btnInsert_Click(object sender, EventArgs e)
        {
            ThemNV();
        }
    }
}
